s = input().split(" ")
n = int(s[0])
m = int(s[1])
arr = [None] * n
for i in range(n):
    arr[i] = [int(x) for x in input().split(" ")]
for col in range(m):
    for i in range(n):
        for j in range(i + 1, n):
            if arr[i][col] > arr[j][col]:
                arr[i][col], arr[j][col] = arr[j][col], arr[i][col]
for i in range(n):
    for j in range(m):
        print(arr[i][j], end=" ")
    print()
